package com.yxt.qmgf.snake.ctrl;



import com.yxt.qmgf.snake.constant.Direction;
import javafx.event.EventHandler;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;


public class SnakeActionController implements EventHandler<KeyEvent> {

    @Override
    public void handle(KeyEvent event) {


        if (event.getEventType().equals(KeyEvent.KEY_PRESSED)) {

            if (event.getCode().getName().equals(KeyCode.LEFT.getName()) && snakeInfoController.current_direction != Direction.R) {
                snakeInfoController.current_direction = Direction.L;
            } else if (event.getCode().getName().equals(KeyCode.RIGHT.getName()) && snakeInfoController.current_direction != Direction.L) {
                snakeInfoController.current_direction = Direction.R;
            } else if (event.getCode().getName().equals(KeyCode.UP.getName()) && snakeInfoController.current_direction != Direction.D) {
                snakeInfoController.current_direction = Direction.U;
            } else if (event.getCode().getName().equals(KeyCode.DOWN.getName()) && snakeInfoController.current_direction != Direction.U) {
                snakeInfoController.current_direction = Direction.D;
            }
        }

    }


}
